package rs.belex.belexdroid.service;

import rs.belex.belexdroid.accessor.InvalidBackendResponse;
import rs.belex.belexdroid.accessor.StockQuoteAccessor;
import rs.belex.belexdroid.accessor.webservicex.StockQuoteAccessorImpl;
import rs.belex.belexdroid.beans.interfaces.StockQuote;
import android.os.Handler;
import android.os.Message;


public class StockQuoteService implements Runnable {
	private String[] symbols;
	private Handler handler;
	private StockQuoteAccessor stockQuoteAccessor;
	
	public StockQuoteService(String[] symbols, Handler handler){
		this.symbols = symbols;
		this.handler = handler;
		stockQuoteAccessor = new StockQuoteAccessorImpl();
	}

	public void run() {
        Message message = Message.obtain();
		try {
			StockQuote[] stockQuotes = stockQuoteAccessor.getStockQuote(symbols);
			message.obj = stockQuotes;
		} catch (InvalidBackendResponse e) {
			message.obj = e;
		}
		this.handler.sendMessage(message);
	}

}
